<!DOCTYPE html>
<html>
<head>
    <title>AZ-204 Question 159</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            line-height: 1.6;
        }
        .question-container {
            border: 1px solid #ddd;
            padding: 20px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        .drag-container {
            display: flex;
            gap: 20px;
            margin: 20px 0;
        }
        .commands {
            width: 40%;
            padding: 15px;
            background-color: #f5f5f5;
            border-radius: 5px;
        }
        .command {
            padding: 10px;
            margin: 8px 0;
            background-color: white;
            border: 2px solid #0078d4;
            border-radius: 4px;
            cursor: move;
        }
        .answer-area {
            width: 60%;
            padding: 15px;
            background-color: #e6f2ff;
            border-radius: 5px;
        }
        .drop-zone {
            min-height: 60px;
            margin: 15px 0;
            padding: 10px;
            border: 2px dashed #0078d4;
            background-color: white;
        }
        .drop-zone.empty {
            background-color: #f9f9f9;
        }
        .answer-button {
            padding: 10px 15px;
            background-color: #0078d4;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        .answer-button:hover {
            background-color: #106ebe;
        }
        .answer {
            margin-top: 20px;
            padding: 20px;
            background-color: #e8f5e9;
            border-radius: 5px;
            display: none;
        }
        .correct-answer {
            font-weight: bold;
            color: #2e7d32;
        }
        .explanation {
            margin-top: 15px;
        }
    </style>
</head>
<body>
    <div class="question-container">
        <h2>QUESTION NO: 159 DRAG DROP</h2>
        <p>You plan to create a Docker image that runs as ASP.NET Core application named ContosoApp.</p>
        <p>You have a setup script named setupScript.ps1 and a series of application files including ContosoApp.dll.</p>
        <p>You need to create a Dockerfile document that meets the following requirements:</p>
        <ul>
            <li>Call setupScript.ps1 when the container is built.</li>
            <li>Run ContosoApp.dll when the container starts.</li>
        </ul>
        <p>The Docker document must be created in the same folder where ContosoApp.dll and setupScript.ps1 are stored.</p>
        <p>Which four commands should you use to develop the solution? To answer, move the appropriate commands from the list of commands to the answer area and arrange them in the correct order.</p>
        
        <div class="drag-container">
            <div class="commands" id="commands">
                <div class="command" draggable="true" data-value="FROM microsoft/aspnetcore:2.0">FROM microsoft/aspnetcore:2.0</div>
                <div class="command" draggable="true" data-value="WORKDIR /apps/ContosoApp">WORKDIR /apps/ContosoApp</div>
                <div class="command" draggable="true" data-value="COPY ./ .">COPY ./ .</div>
                <div class="command" draggable="true" data-value="RUN powershell /setupScript.ps1">RUN powershell /setupScript.ps1</div>
                <div class="command" draggable="true" data-value="EXPOSE /ContosoApp/ /apps/ContosoApp">EXPOSE /ContosoApp/ /apps/ContosoApp</div>
                <div class="command" draggable="true" data-value="CMD powershell /setupScript.ps1 ENTRYPOINT [\"dotnet\",\"ContosoApp.dll\"]">CMD powershell /setupScript.ps1 ENTRYPOINT ["dotnet","ContosoApp.dll"]</div>
            </div>
            
            <div class="answer-area">
                <h3>Answer Area (Drag 4 commands here in order)</h3>
                <div class="drop-zone empty" id="drop1"></div>
                <div class="drop-zone empty" id="drop2"></div>
                <div class="drop-zone empty" id="drop3"></div>
                <div class="drop-zone empty" id="drop4"></div>
            </div>
        </div>
        
        <button class="answer-button" id="showAnswer">查看答案</button>
        
        <div class="answer" id="answer">
            <h3>正确答案:</h3>
            <ol class="correct-answer">
                <li><strong>WORKDIR /apps/ContosoApp</strong>1.首先设置工作目录</li>
                <li><strong>COPY ./ .</strong>2.然后复制当前目录所有文件到容器</li>
                <li><strong>EXPOSE ./ContosApp/ /app/ContosoApp</strong>3.接着暴露必要的应用目录</li>
                <li><strong>CMD powershell ./setupScript.ps1</br>ENTRYPOINT ["dotnet", "ContosoApp.dll"]</strong>4.最后配置容器启动时要运行的命令（先执行PowerShell脚本，然后运行dotnet应用）</li>
            </ol>
            <div class="explanation">
                <h4>说明:</h4>
                <p>其他：</p>
                <ol>
                    <li><strong>FROM microsoft/aspnetcore:2.0</strong> - 指定基础镜像</li>
                    <li><strong>WORKDIR /apps/ContosoApp</strong> - 设置工作目录</li>
                    <li><strong>COPY ./ .</strong> - 将当前目录文件复制到容器中</li>
                    <li><strong>RUN powershell /setupScript.ps1</strong> - 在构建时运行设置脚本</li>
                </ol>
                <p>参考文档中关于创建自定义Docker镜像的教程也支持这种配置方式。这个解决方案满足了题目中列出的所有要求：</p>
                <ul>
                    <li>在构建时调用setupScript.ps1</li>
                    <li>在容器启动时运行ContosoApp.dll</li>
                    <li>Dockerfile与应用程序文件位于同一目录  </li>
                </ul>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const commands = document.querySelectorAll('.command');
            const dropZones = document.querySelectorAll('.drop-zone');
            const showAnswerBtn = document.getElementById('showAnswer');
            const answerDiv = document.getElementById('answer');
            
            let draggedCommand = null;
            
            // Drag events for commands
            commands.forEach(command => {
                command.addEventListener('dragstart', function() {
                    draggedCommand = this;
                    setTimeout(() => {
                        this.style.opacity = '0.4';
                    }, 0);
                });
                
                command.addEventListener('dragend', function() {
                    this.style.opacity = '1';
                });
            });
            
            // Drop events for zones
            dropZones.forEach(zone => {
                zone.addEventListener('dragover', function(e) {
                    e.preventDefault();
                    this.style.backgroundColor = '#d4e6ff';
                });
                
                zone.addEventListener('dragleave', function() {
                    this.style.backgroundColor = '';
                });
                
                zone.addEventListener('drop', function(e) {
                    e.preventDefault();
                    this.style.backgroundColor = '';
                    
                    // Remove from any previous zone
                    dropZones.forEach(z => {
                        if (z.contains(draggedCommand)) {
                            z.removeChild(draggedCommand);
                            z.classList.add('empty');
                        }
                    });
                    
                    // Clear this zone first
                    while (this.firstChild) {
                        this.removeChild(this.firstChild);
                    }
                    
                    // Add the command to this zone
                    const clone = draggedCommand.cloneNode(true);
                    clone.style.opacity = '1';
                    clone.draggable = false;
                    this.appendChild(clone);
                    this.classList.remove('empty');
                });
            });
            
            // Show answer button
            showAnswerBtn.addEventListener('click', function() {
                answerDiv.style.display = 'block';
            });
        });
    </script>
</body>
</html>
